package edu.yctc.manage.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import edu.yctc.manage.constant.KaptchaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * @author zyj
 * @className KaptchaConfig
 * @description 图片验证码配置类
 * @date 2020年6月15日
 */
@Component
public class KaptchaConfig {

    public static final String BLACK = "black";
    public static final String WIDTH = "150";
    public static final String HEIGHT = "40";
    public static final String FONT_SIZE = "30";
    public static final String VERIFY_CODE = "verifyCode";
    public static final String CHAR_SPACE = "5";

    @Bean
    public DefaultKaptcha getDefaultKaptcha() {
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        properties.put(KaptchaProperties.BORDER, KaptchaProperties.BORDER_WITHOUT);
        properties.put(KaptchaProperties.FONT_COLOR, BLACK);
        properties.put(KaptchaProperties.IMAGE_WIDTH, WIDTH);
        properties.put(KaptchaProperties.IMAGE_HEIGHT, HEIGHT);
        properties.put(KaptchaProperties.FONT_SIZE, FONT_SIZE);
        properties.put(KaptchaProperties.SESSION_KEY, VERIFY_CODE);
        properties.put(KaptchaProperties.CHAR_SPACE, CHAR_SPACE);
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }

}
